package learningThread.juc;

import learningThread.api.commonAndNot.MyRunable;

import java.util.concurrent.CountDownLatch;

/**
 * CountDownLatch可控制线程的执行,子线程优先于主线程执行完成
 */
public class MyCountDownLatch {



    public static void main(String[] args) {
        CountDownLatch countDownLatch = new CountDownLatch(5);
        Thread[] tds = new Thread[5];
        for (int i = 0; i < 5; i++) {
            MyRunnable myRunnable = new MyRunnable(countDownLatch);
            tds[i] = new Thread(myRunnable);
        }
        for (int i = 0; i < tds.length; i++) {
            tds[i].start();
        }
        try {
            countDownLatch.await();
            System.out.println("主线程执行:"+System.currentTimeMillis());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }



}
